<template>
  <a-card>
    <a-spin :spinning="spinning">
      <a-descriptions :column="1">
        <a-descriptions-item label="商品类型">{{ dataObj.goodsType | goodsType }}</a-descriptions-item>
        <a-descriptions-item label="会员卡名">{{ dataObj.name }}</a-descriptions-item>
        <a-descriptions-item label="会员卡类型">{{ dataObj.memberType | memberType }}</a-descriptions-item>
      </a-descriptions>
      <a-divider style="margin-bottom: 32px" />
      <a-descriptions :column="1">
        <a-descriptions-item label="描述">{{ dataObj.label }}</a-descriptions-item>
        <a-descriptions-item label="介绍"
          ><div class="goods-content">{{ dataObj.content }}</div></a-descriptions-item
        >
        <a-descriptions-item label="价格">{{ dataObj.price }} 元</a-descriptions-item>
        <a-descriptions-item label="有效期">{{ dataObj.days }} 天</a-descriptions-item>
        <a-descriptions-item label="图标">
          <div class="img-box">
            <img :src="dataObj.posterImg" alt="" class="icon-img" />
          </div>
        </a-descriptions-item>
      </a-descriptions>
    </a-spin>
  </a-card>
</template>
<style scoped>
.goods-content {
  word-wrap: break-word;
}
.img-box {
  width: 104px;
  height: 104px;
  box-sizing: border-box;
  padding: 8px;
  margin-right: 8px;
  margin-bottom: 8px;
  text-align: center;
  background-color: #fafafa;
  border: 1px dashed #d9d9d9;
  border-radius: 2px;
  cursor: pointer;
  -webkit-transition: border-color 0.3s ease;
  transition: border-color 0.3s ease;
}
.icon-img {
  width: 86px;
  height: 86px;
}
</style>
<script>
import { goodsDetail } from '@/api/box/product'
export default {
  data() {
    return {
      spinning: true,
      dataObj: {}
    }
  },
  filters: {
    goodsType(value) {
      if (value === 2000) {
        return '会员卡'
      }
    },
    memberType(value) {
      if (value === 1) {
        return '订阅卡'
      } else if (value === 2) {
        return ' 体验卡'
      }
    },
    price(value) {
      return value / 100
    }
  },
  activated() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      const id = this.$route.params.id
      const data = {
        requestData: id
      }
      goodsDetail(data)
        .then(res => {
          console.log(res)
          if (res.code === 0) {
            this.dataObj = res.data
            this.dataObj.price = this.dataObj.price / 100
            // console.log(this.imageUrl)
            this.spinning = false
          } else {
            this.spinning = false
            this.$message.error(res.msg)
          }
        })
        .catch(err => {
          console.log('fetchData:' + err)
        })
    }
  }
}
</script>
